package com.dimao.certificate_build_service.pdf;

import com.itextpdf.forms.fields.PdfFormField;
import com.itextpdf.kernel.font.PdfFont;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

import java.util.List;
import java.util.Map;

public class TypeTwoValue extends Value {
    @Override
    protected String additionalOperating(Map<String, PdfFormField> formMap, List<PdfFont> fonts, JsonObject jsonObject) {
        JsonArray jsonArray = jsonObject.getJsonArray("teachers");
        PdfFont fontTwo = fonts.get(1);
        PdfFont fontThree = fonts.get(2);

        formMap.get("date")
                .setValue(jsonObject.getString("date"), fontThree, 15.0f);

        if((jsonArray != null) && (!jsonArray.isEmpty())){
            for(int i = 0; i < (jsonArray.size() - 1); i++){
                String key = "teacher" + (i + 1);
                String value = addSpaceToFourUtf8Chars(jsonArray.getString(i));
                formMap.get(key)
                        .setValue(value + "、", fontTwo, 19.0f);
            }

            String key = "teacher" + jsonArray.size();
            String value = addSpaceToFourUtf8Chars(jsonArray.getString(jsonArray.size() - 1));
            formMap.get(key).setValue(value, fontTwo, 19.0f);
        }

        return "";
    }
}
